package com.web.cms.pan.provider;

import com.blue.jdbc.Page;
import com.web.cms.pan.exception.UserInfoException;
import com.web.cms.pan.facade.UserInfoFacade;
import com.web.cms.pan.message.OperatorLogRequest;
import com.web.cms.pan.message.OperatorLogResponse;
import com.web.cms.pan.message.UserInfoResponse;
import com.web.cms.pan.model.OperatorLog;
import com.web.cms.pan.model.UserInfo;
import com.web.cms.pan.service.UserInfoService;
import com.web.cms.pan.util.OperatorLogConvertor;
import com.web.cms.pan.util.UserInfoConvertor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 用户网盘信息接口实现类
 * 
 * @author 代码由 blue-code 框架生成
 * @since 1.0 2018年04月09日
 */
@Component("panUserInfoProvider")
public class UserInfoProvider implements UserInfoFacade
{
	@Autowired
	private UserInfoService userInfoService;
	
	public UserInfoProvider()
	{
	}

	@Override
	public UserInfoResponse get(Integer id)
	{
		if (id == null)
			throw new UserInfoException("ID不能为空");

		UserInfo userInfo = userInfoService.get(id);
		UserInfoResponse response = UserInfoConvertor.toResponse(userInfo);
		return response;
	}

	@Override
	public Map<Integer, UserInfoResponse> getList(List<Integer> idList)
	{
		if (idList == null || idList.isEmpty())
			return new HashMap<>();

		Map<Integer, UserInfo> map = userInfoService.getList(idList);
		Map<Integer, UserInfoResponse> responseMap = UserInfoConvertor.toResponse(map);
		return responseMap;
	}

	@Override
	public Page<OperatorLogResponse> listLogPage(OperatorLogRequest request, int start, int size)
	{
		OperatorLog operatorLog = OperatorLogConvertor.toOperatorLog(request);
		Page<OperatorLog> page = new Page<>(size);
		page.setCurPage(start);
		page = userInfoService.listLog(operatorLog, page);
		Page<OperatorLogResponse> pageResponse = OperatorLogConvertor.toResponse(page);
		return pageResponse;
	}
	
}
